/*
 * Tupla.cpp
 *
 *  Created on: 19/12/2013
 *      Author: root
 */

#include <stdlib.h>
#include <list>

using namespace std;

int * crearTuplaVacia(int size){

	int * t = new int[size];
	for(int i = 0; i < size; i++)
		t[i] = -1;

	return t;
}

int getPosTupla(int * t, int size){

	for(int i=0; i < size; i++){

		if(t[i] == -1)
			return i;
	}
	return -1;
}


int ** crearPaquete(int size){

	int** r = new (int*)[size];

	for(int i = 0; i < size; i++){
		r[i] = NULL;
	}

	return NULL;
}


void agregarTuplaPaq(int **& p, int size, int * &t, int sizeT){

	for(int i = 0; i < size ; i++){

		if (p[i] != NULL){

			p[i] = new int[sizeT];
			for(int j = 0; j < sizeT; j++){
				p[i][j] = t[j];
			}
			return;
		}

	}

}

void destruirPaquete(int ** &p, int size){

	for(int i = 0; i < size ; i++){

		delete[] p[i];
	}
	delete[] p;
	p = NULL;
}


void crearPaquete(list<int*> &lt, int sizeT , int cantProc, int &sizeEnv, int ** &ret){
	int ltsize = lt.size();
	int cociente = ltsize / cantProc;
	int resto = ltsize % cantProc;

	sizeEnv = (cociente + resto) * sizeT;

	ret = new int*[cantProc];
	int i = 0;
	int j;
	list<int*>::iterator it = lt.begin();
	while( i < cantProc){
		j = 0;
		ret[i] = new int[sizeEnv];
		while(j < cociente && it != lt.end()){
			int kaux = 0;

			for(int k = 0; k < sizeT; k++){
				ret[i][kaux] = it[k];
				kaux++;
			}

			it++;
			j++;

		}

		if(ltsize < resto){



		}

		i++;

	}

	lt.clear();
	lt = NULL;

}

